package com.hellpro.lolbox.home.model;

import android.content.Context;

import com.google.gson.reflect.TypeToken;
import com.hellpro.lolbox.bean.ZXTab;
import com.hellpro.lolbox.home.HomeJsonUtils;
import com.hellpro.lolbox.utils.OkHttpClientUtils;

import org.greenrobot.eventbus.EventBus;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.List;

/**
 * Package_Name: com.hellpro.lolbox.home.model
 * Description :
 * author: HellPermanent
 * date:  2016/10/20 21:52
 * remarks：
 */
public class ZXTabModel {
    private String mUrl;
    private Context mContext;

    public ZXTabModel(Context context,String url){
        mContext =context;
        mUrl =url;
        loadTabData();
    }
    public void loadTabData(){

        new Thread(new Runnable() {
            @Override
            public void run() {
                String path = mUrl;
                try {
                    if (path!=null) {
                        String tabData = OkHttpClientUtils.getStringFromURL(mContext, path, null);
                       if (tabData!=null) {

                           Type type = new TypeToken<List<ZXTab>>() {
                           }.getType();
                           List<ZXTab> data = (List<ZXTab>) HomeJsonUtils.getArrayData(tabData, type);
                        
                               EventBus.getDefault().post(data);

                       }else {
                           return;
                       }
                    }else {
                        return;}

                } catch (IOException e) {
                }
            }
        }).start();

    }
}
